/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CustomComponents;

import AreaDeDesenho.PainelDeDesenho;
import Helpers.EFormas;
import Helpers.ETransformacoes;
import Helpers.Funcoes;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.LinkedBlockingQueue;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

/**
 *
 * @author Lilli
 */
public class JCustomToggleButton extends JToggleButton implements ActionListener {

    EFormas forma;

    public JCustomToggleButton(EFormas forma) {
        this.forma = forma;
        this.addActionListener(this);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        LinkedBlockingQueue<ETransformacoes> list = new LinkedBlockingQueue<ETransformacoes>();
        list.add(ETransformacoes.None);
        Funcoes.desenhaForma(this.forma,Color.BLACK, g, 5, 5, this.getSize().width - 10, this.getSize().height - 10, 5, 5, 1,-1,-1);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

        if (this.isSelected()) {
            PainelDeDesenho.setFormaAtual(forma);
            if (this.getParent() != null && this.getParent() instanceof JPanel) {
                JPanel aux = (JPanel) this.getParent();
                for (Component comp : this.getParent().getComponents()) {
                    if (comp instanceof JCustomToggleButton && comp != this) {
                        ((JCustomToggleButton) comp).setSelected(false);
                    }
                }
            }
        } else {
            PainelDeDesenho.setFormaAtual(EFormas.NONE);
        }
    }
}
